package com.sfdk.locale
{
    import com.sfdk.io.GenericIO;

    /**
     * Classe LocalisedEngine de haut niveau
     * On set la locale au depart et ensuite en utilisant getMessage on recupère ce qu'on veut dans la bonne langue
     **/

    public class LocalisedMessageEngine extends GenericIO
    {
        private static var localisedEngine_:LocalisedMessageEngine;

        private var currentLocale_:String;
        private var _messageData:XML;

        public function LocalisedMessageEngine(locale:String):void {
            localisedEngine_ = this;
            currentLocale_ = locale.toLowerCase();

            super("resources/messages/" + currentLocale_ + "/messageInfo.xml");
        }


        override protected function init():void {
            super.init();
            _messageData = getFileData();
        }

        public function getMessageContent(message:String):String {
            var localeMessage:XMLList = _messageData.elements(message);
            return (localeMessage[0] as XML);
        }

        public static function getMessage(message:String):String {
            var out:String = localisedEngine_.getMessageContent(message);
            if (out == null)
                return "";
            else
                return out.replace(/\\n/g, "\n");
        }
    }
}